home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 October / MACPOWER-1997-10.ISO.7z / MACPOWER-1997-10.ISO / AMUG / PROGRAMMING / Mac F2C 1.3.5.sit / Mac F2C 1.3.5 / Mac F2C v1.3.5 Documentation.rsrc / TEXT_138.txt < prev    next >
Text File  |  1997-06-15  |  15KB  |  167 lines

  1. Using Mac F2C With THINK C/C++ for 68K
  2.  
  3.  
  4. Before you can use the code produced by Mac F2C, you must set up and build all of the required support libraries.  There are also special rules that must be followed when using code produced by Mac F2C.  The process and rules are slightly different for each compiler.  These instructions are for setting up Mac F2C for use with THINK C/C++ for 68K.  Refer to other chapters for instructions on how to set things up for use with Symantec C/C++ for PPC or Metrowerk窶冱 CodeWarrior C/C++ compilers.
  5.  
  6. Users upgrading from earlier versions need to re-install all libraries, project files, and supporting files.  All files, including library source code, have been updated in version 1.3.    
  7.  
  8.  
  9. Important Changes for Users Upgrading
  10.  
  11. 窶「 Do not place the source code to the Mac F2C Libraries in the folder containing the THINK Project Manager application or in any of it窶冱 sub-folders).  There are name conflicts between the files in libI77/libF77 and some of the new universal header files and PPC support files.  This means you must build the F2C libraries first and then copy the built libraries into the THINK Project Manager tree.
  12.         
  13. 窶「 To accomodate PPC versions, the THINK libraries libI77a, libI77b, and libF77 have been renamed libI77a 68K, libI77b  68K, and libF77 68.  You may either modify your existing projects or simply rename these libraries to their old names after you have built them.
  14.         
  15. All of the THINK project files shipped with Mac F2C are for the THINK Project Manger (TPM) version 7.0.5 (the version that ships with Symantec C/C++ Version 8, Release 4).  
  16.  
  17. If you are using THINK v7.0.4 (the latest version you can update to for free), you can find 7.0.4 versions of all the project files and stationary files in the folder TPM 7.0.4 Project Files (located in the TPM Support folder).  Simply replace all the project files and stationary files referred to in these instructions with the corresponding files of the same name from the TPM 7.0.4 Project Files folder.  
  18.  
  19. If you have THINK v6 or an earlier v7, use the free updaters provided by Symantec to bring your copy of THINK up to v7.0.4.  
  20.  
  21. If you are using a version of THINK older than v7, please refer to the additional instructions in the chapter 窶弋HINK pre-v7 and Other Compilers窶.
  22.  
  23.  
  24. Setting Up Mac F2C Using the Installer
  25.  
  26. The easiest way to set up Mac F2C is to use the installer included with Mac F2C.  This installer will only work correctly if you have System 7.5 (or higher) and have THINK v7.  If you do not meet both of these requirements, please follow the instructions for manual installation found in the following section.  If you are using an earlier version of THINK, please also refer to the additional instructions in the chapter 窶弋HINK pre-v7 and Other Compilers窶.
  27.  
  28. The installer is stand-alone AppleScript application called Mac F2C Installer.  To run the installer, simply double click on it, and answer the dialogs it presents.  The installer will do the following:
  29.  
  30. 窶「 Create a folder called Mac F2C Support within the folder containing the THINK Project Manager.
  31. 窶「 Copy the Mac F2C versions of the THINK standard libraries.
  32. 窶「 Build the appropriate Mac F2C libraries.
  33. 窶「 Move the built libraries to the Mac F2C Support folder.
  34. 窶「 Copy the Mac F2C project models to THINK窶冱 (Project Models) folder.
  35. 窶「 Translate and build the appropriate versions of the test application.
  36.  
  37. When the installer is finished, you will find completed test applications in the Test Project ニ’ folder.  You should run these to verify correct operation of Mac F2C and its libraries.  After that, you are ready to go.  To compile translated FORTRAN code, simply open a new project in the THINK Project Manager, select the appropriate version of Mac F2C project models, and add the translated files.
  38.  
  39. The remaining sections provide step-by-step instructions for installing Mac F2C manually, a more detailed description of how to test your Mac F2C installation, and additional information on using code generated by Mac F2C with THINK Project Manager.
  40.  
  41.  
  42. Setting Up Mac F2C Manually
  43.  
  44. All the files and folders you need are contained in the folder TPM Support (which is located within the folder Symantec/THINK Support).  Unless otherwise indicated, all files and folders referred to in the following sections are located in this folder.  TPM refers to the THINK Project Manager.
  45.  
  46. Step 1:  Bring all the libraries up-to-date
  47.  
  48. The Mac F2C libraries come without binaries, so you have to build them according to the following algorithm:
  49.  
  50. FOR the project files:
  51.    (1) libI77a 68K     (in Mac F2C Libraries folder)
  52.    (2) libI77b 68K     (in Mac F2C Libraries folder)
  53.    (3) libF77 68K      (in Mac F2C Libraries folder)
  54. REPEAT the following steps:
  55.     (a) Double-click on the project file.  
  56.     (b) In the THINK Project Manager窶冱 Source menu, 
  57.          select the Make command.  
  58.     (c) Uncheck the Quick Scan check-box.  
  59.     (d) Click on the Use Disk button.  
  60.     (e) Click on the Make button.
  61. END FOR-REPEAT
  62.  
  63. Step 2: Move things to the recommended locations
  64.  
  65. For easiest and smoothest operation, files should be installed as follows: 
  66.  
  67. 窶「 The folder For 'Standard Libraries'  contains four TPM project files:  ANSI F2C, unix F2C, IOStreams F2C, and CPlusLib F2C.  Drag these files (not the folder itself) to the Standard Libraries folder located in the same folder as the TPM application.  If you don窶冲 have the THINK C++ compiler (or you don窶冲 plan to use Mac F2C with it) you do not need IOStreams F2C or CPlusLib F2C.
  68.  
  69. 窶「 Create a folder called Mac F2C Support inside the folder within the  folder that contains the THINK Project Manager (TPM) application.  
  70.  
  71. 窶「 Drag the three TPM project files in the folder Mac F2C Libraries (libI77a 68K, libI77b 68K, and libF77 68K; the same ones you brought up-to-date in Step 2 above) to the Mac F2C Support folder which you just created.   
  72.  
  73. WARNING:  Do not place the source code for these libraries (found in the folders libF77 Sources and libI77 Sources) in the folder containing the THINK Project Manager application or in any of it窶冱 sub-folders).  The source code for these libraries has name conflicts with Apple窶冱 Universal Headers (e.g., a file called fp.h appears in both but the two are NOT equivalent files).  Otherwise any of your code that #includes any of the conflicted files may inadvertently access the wrong file.
  74.  
  75. 窶「 The folder For '(Project Models)' (located one level up in the TPM Support Folder) contains two model project folders called TPM Mac F2C C Project and TPM Mac F2C C++ Project.  Drag both folders to the (Project Models) folder located in the same folder as the TPM (if you don窶冲 have THINK C++ or don窶冲 plan to use Mac F2C with the C++ compiler, you don窶冲 need the TPM Mac F2C C++ Project folder).  
  76.  
  77.  
  78. Verifying Correct Operation of Mac F2C
  79.  
  80. The folder Test Project ニ’ contains the following files:
  81.  
  82. test.f -- a sample FORTRAN program.
  83.  
  84. F2Cmain.c -- the main program required to run programs produced by  Mac F2C.
  85.  
  86. F2Cmain.cp -- the main program required to run programs produced by  Mac F2C.
  87.  
  88. f2c.h -- an include file required to compile programs produced by Mac F2C.
  89.  
  90. test.c (Output) -- what you should get when you translate the sample FORTRAN code files.
  91.  
  92. Test.68K.マ\ -- a TPM v7.0.4 project to run the sample C program.
  93.   
  94. test.c (C++ Output) -- what you should get when you translate 
  95. the sample FORTRAN code files and select the C++ output option.
  96.  
  97. Test++.68K.マ\ -- a TPM v7.0.4 project to run the sample C++ program.
  98.  
  99. Test.PPC.マ\ and Test++.PPC.マ\ -- SPM v8.0.1 project files to run the sample program.
  100.     
  101. Test++.*.ツオ -- CodeWarrior project files to run the sample program. 
  102.     
  103. Translate the sample FORTRAN program Test.f simply by dragging it onto Mac F2C.  Do not change any of the options (use Factory Defaults).  Once you have done this you can compare it with Test.c (C Output) file to verify that you got the same thing.  If so, double click on the TPM project Test.68K.マ\ and run it to verify correct operation.
  104.  
  105. If you also plan to use Mac F2C C++ output with the Codewarrior, you can run a second test to verify correct operation with the C++ compiler.  Start Mac F2C and in the C Options dialog, select C++ code.  Do not change any of the other options.  Translate Test.f.  Compare it with Test.cp (C++ Output) to verify that you got the same thing.  If so, double click on the CPM project Test++.68K.マ\ and run it to verify correct operation.
  106.  
  107.  
  108. Using C Code Generated by Mac F2C
  109.  
  110. The C code produced by Mac F2C has the following compile and link requirements when using THINK to generate code for the 68K:
  111.  
  112.     窶「 the header file:
  113.           f2c.h
  114.     窶「 the F2C libraries: 
  115.                                         libI77a 68K
  116.           libI77b 68K 
  117.                                         libF77 68K
  118.     窶「 the THINK libraries: 
  119.         ANSI F2C
  120.         unix F2C
  121.     窶「 for C++ code only, the THINK libraries:
  122.         IOStreams F2C
  123.         CPlusLib F2C
  124.     窶「 4-byte integers  (C only)
  125.     窶「 8-byte doubles
  126.     窶「 Native Floating-Point Format
  127.     窶「 Far Code
  128.     窶「 Far Data
  129.     窶「 C++ ANSI Conformance unchecked (C++ only)
  130.  
  131. In addition, if you compile a stand-alone FORTRAN program (instead of only some FORTRAN subroutines) you must include F2Cmain.c in your project (or F2Cmain.cp if you use C++; the two files are identical).  This is because the original main routine in the FORTRAN program becomes a function that is called by F2Cmain.c.  In addition, F2Cmain.c performs a series of initializations (primarily related to error catching) prior to executing the main FORTRAN program.
  132.  
  133. The model project provided (TPM Mac F2C C Project) is a folder that contains everything you need to compile and run code produced by Mac F2C using the C compiler.  This folder has a copy of F2Cmain.c, f2c.h, and a project file that includes the appropriate libraries and option settings.
  134.  
  135. The C++ model project (TPM Mac F2C C++ Project) is a folder that contains everything you need to compile and run code produced by Mac F2C using the C++ compiler.  This folder has a copy of F2Cmain.cp, f2c.h, and a project file that includes the appropriate libraries and option settings.
  136.  
  137. If you have THINK C version 7.0 or better, simply create a new project by using the New Project command in the THINK Project Manager窶冱 File menu and selecting TPM Mac F2C C Project or TPM Mac F2C C++ Project as the model for the new project.  Add your code files as appropriate, bring it up-to-date (you may need to use the Make command and the Use Disk option the first time), and run.
  138.  
  139. If you have an earlier version of THINK C, first replace the project file 
  140. provided in Mac F2C C Project with one made with your version of THINK (I have included a list of the project contents for your convenience窶敗ee the additional instructions in the chapter 窶弋HINK pre-v7 and Other Compilers窶 if you have trouble doing this).  Do not include any objects at this time.  To start a new project, duplicate the entire Mac F2C C Project folder, change the names of files and folders as appropriate, add your code files, and bring everything up-to-date.
  141.  
  142. If you compile a FORTRAN subroutine or function that you want to call from a C program, look at the output C code to see the appropriate calling protocol.  You may or may not need to include the F2C support libraries (libF77 68K, libI77a 68K, and libI77b 68K).  In rare cases, you may also need to copy some of the initialization code from F2Cmain.c to your calling program.
  143.  
  144.  
  145. Special 68K Considerations
  146.  
  147. Please read the following section carefully if you intend to use Mac F2C with the THINK compiler generating 68K code:
  148.  
  149. As noted above, code produced by Mac F2C MUST be compiled with 4-byte integers.  This requirement cannot be relaxed.  The other requirements (8-byte doubles, native floating-point format, far code, and far data) can sometimes be relaxed:
  150.  
  151. IF you do not use doubles in any situation where their size relative to reals matters (e.g., if you do not use doubles in equivalence and common statements), then your code probably does not require 8-byte doubles.  You need to verify this on a case-by-case basis.
  152.  
  153. This requirement exists because Mac F2C follows FORTRAN sizing rules when compiling FORTRAN code:  sizeof(real) == sizeof(integer) and sizeof(double) == 2*sizeof(real).  FORTRAN real is compiled as  C float and FORTRAN double as C double, so doubles have to be 8-bytes long for equivalence and common statements to be properly aligned.  There are a few other cases where the size of double variables matters; see AT&T Computing Science Technical Report  No. 149 (included with Mac F2C) for a detailed discussion.
  154.         
  155. IF you compile your program with the option Local variables are automatic and you do not have large static data structures, you might not need Far Data.  You need to verify this on a case-by-case basis.
  156.         
  157. Mac F2C creates large static data structures for I/O.  If you create local variables in the global area (static instead of automatic) or  if you have other static data, you will almost certainly require Far Data.  The I/O data structures can be large enough that you may  require Far Data for that reason alone.  
  158.  
  159. IF your program is not very large and doesn窶冲 have a large number of subroutines, you probably will not need Far Code.  You need to verify this on a case-by-case basis.
  160.         
  161. Mac F2C tends to produced redundant copies of utility code (especially code for performing array indexing).  It can also produce large numbers of auxiliary functions.  The result is that Far Code is often required.  Compile first with Far Code, then check the code size and jump table to see if you can relax this requirement.
  162.         
  163. IF your program will not be compiled under THINK C++ (i.e., you chose K&R C or ANSI C output instead of C++ output) and you will  not link with code produced by THINK C++, you do not need native floating-point format.  The native floating-point format option is selected only to guarantee compatibility with the THINK C++ compiler should you chose to use the output of Mac F2C with C++ code.
  164.         
  165. If you change the 8-byte doubles, native floating-point format, Far Code, or Far Data options, remember to also change them in all the libraries, specifically libI77a 68K, libI77b 68K, libF77 68K, ANSI F2C, unix F2C, IOStreams F2C, and CPlusLib F2C (the latter two for C++ only).
  166.  
  167. I urge all users to read the enclosed AT&T Computing Science Technical Report No. 149.  Consider it your compiler and language reference manual.